var path = require('path')
var HtmlwebpackPlugin = require('html-webpack-plugin')
var webpack = require('webpack')

var ROOT_PATH = path.resolve(__dirname)
var APP_PATH = path.resolve(ROOT_PATH, 'app')
var BUILD_PATH = path.resolve(ROOT_PATH, 'build')

module.exports = {
    // 项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字
    // entry: APP_PATH,
    entry: {
        app: APP_PATH,
        vendor: ['moment']
    },
    //输出的文件名 合并以后的js会命名为bundle.js
    output: {
        path: BUILD_PATH,
        filename: 'bundle.js'
    },
    module: {
        rules: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: ['es2015']
                }
            }]
        }, {
            test: /\.css$/,
            loaders: ['style-loader', 'css-loader']
        }, {
            test: /\.scss$/,
            loaders: ['style-loader', 'css-loader', 'sass-loader']
        }, {
            test: /\.(png|jpg)$/,
            loader: 'url-loader?limit=40000'
        }]
    },
    plugins: [
        // 这个插件使用uglifyJs压缩js代码
        new webpack.optimize.UglifyJsPlugin({
            minimize: true
        }),
        // 把入口配置中的数组打包成verdors.js
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor',
            filename: "vendor.js"
        }),
        new HtmlwebpackPlugin({
            title: '你好,webpack.'
        })
    ],
}
